package com.example.android2019.ch6service;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.android2019.R;

public class ServiceActivity extends AppCompatActivity {
    Button btn1, btn2, btn3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_service);
        btn1 = findViewById(R.id.ch6_service_btn1);
        btn2 = findViewById(R.id.ch6_service_btn2);
        btn3 = findViewById(R.id.ch6_service_btn3);
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.ch6_service_btn1:
                        Intent intent1 = new Intent(ServiceActivity.this, Service1Activity.class);
                        intent1.putExtra("test", "tz");
                        startActivity(intent1);
                        break;
                    case R.id.ch6_service_btn2:
                        Intent intent2 = new Intent(ServiceActivity.this, Service2Activity.class);
                        intent2.putExtra("test", "tz");
                        startActivity(intent2);
                        break;
                    case R.id.ch6_service_btn3:
                        Intent intent3 = new Intent(ServiceActivity.this, ImageActivity.class);
                        intent3.putExtra("test", "tz");
                        startActivity(intent3);
                        break;
                }
            }
        };
        btn1.setOnClickListener(listener);
        btn2.setOnClickListener(listener);
        btn3.setOnClickListener(listener);

         /*获取传递的数据*/
        Intent intent = this.getIntent();
        String a = intent.getStringExtra("test");
        Toast.makeText(this, a, Toast.LENGTH_SHORT).show();
    }
}
